const initData = {
  // wx1adbb636937baef0: {
  //   name: '中尔企业管理',
  //   loginPage: '/DIYPages/login/login',    //登录跳转页面
  //   indexPage: '/pages/index/index',   //首页跳转页面
  //   indexPage: '/pages/home/home',   //测试方通页面
  //   defSystemId: 800
  // },
  // wx1adbb636937baef0: {
  wxa6bb52a95207e8ab: {
    name: '方通渣土沙石',
    loginPage: '/pages/login/login',
    indexPage: '/pages/home/home',
    defSystemId: 1164
  },
  wx6c99b9c67ec88087: {
    name: '方通渣土挖运',
    loginPage: '/pages/login/login',
    indexPage: '/pages/home/home',
    defSystemId: 1174
  },
  wx8aa2d2af63243c3a: {
    name: '友程企业经营管理系统',
    loginPage: '/repairPages/service_login/service_login',
    indexPage: '/repairPages/service_login/service_login',
    defSystemId: 1140
  },
  // 中尔测试阳晖版
  // wx1adbb636937baef0: {
  //   name: '中尔测试阳晖版',
  //   loginPage: '/repairPages/service_login/service_login',
  //   indexPage: '/repairPages/service_login/service_login',
  //   defSystemId: 1179
  // },
  default: {
    name: '中尔企业管理',
    loginPage: '/DIYPages/login/login',
    indexPage: '/pages/index/index',   //首页跳转页面
    defSystemId: 800
  }

}

const getWXInfo = function (params) {
  let info = wx.getAccountInfoSync(),
    { appId = '' } = info?.miniProgram;
  return appId;
}

export const setWxInfoStorage = function () {
  let appId = getWXInfo(),
    thisInfo = initData[appId] || initData.default;
  let prefix = 'wxinfo';
  for (let key in thisInfo) {
    let val = thisInfo[key]
    wx.setStorageSync(`${prefix}-${key}`, val)
  }
}

export const redirectLogin = function (params) {
  let appId = getWXInfo(),
    thisInfo = initData[appId] || initData.default;
  return new Promise(resolve => {
    wx.reLaunch({
      url: thisInfo.loginPage,
      complete () {
        resolve();
      }
    });
  })
}

export const redirectIndex = function (params) {
  let appId = getWXInfo(),
    thisInfo = initData[appId] || initData.default;
  console.log(appId);
  console.log(thisInfo);
  return new Promise(resolve => {
    console.log(666)
    wx.redirectTo({
      url: '/pages/home/home',
      complete () {
        resolve();
      }
    });
  })
}

